#include "GuiButtonMenu.hpp"

GuiButtonMenu::GuiButtonMenu(int id, int x, int y, std::string displayString)
{
    GuiButtonMenu(id, x, y, 200, 40, displayString,0);
}

GuiButtonMenu::GuiButtonMenu(int id, int x, int y, int width, int height, std::string displayString)
{
    GuiButtonMenu(id, x, y, width, height, displayString, 0);
}

GuiButtonMenu::GuiButtonMenu(int id, int x, int y, int width, int height, std::string displayString, int actualState)
{
    m_id = id;
    rect.left = x;
    rect.top = y;
    rect.width = width;
    rect.height = height;
    m_drawButton = true;
    m_displayString = displayString;
    state = actualState;
    if (!m_texture.loadFromFile("Ressources/Sprites/GuiMenu.png"))
    {
        std::cout<<"Une erreur est survenue, impossible de charger le fichier" << std::endl;
    }
    m_sprite.setTexture(m_texture);
}

GuiButtonMenu::~GuiButtonMenu()
{

}


void GuiButtonMenu::draw(Core* core)
{
    if (m_drawButton)
    {
        m_sprite.setPosition(rect.left, rect.top);
        switch (getState())
        {
            case -1://DISABLED
                m_sprite.setTextureRect(sf::IntRect(0,3*rect.height,rect.width,rect.height));
                core->rWindow.draw(m_sprite);
                core->fontRenderer->printCenteredString(m_displayString, rect, sf::Color(0,0,0),24);
                break;
            case 0://NORMAL
                m_sprite.setTextureRect(sf::IntRect(0,rect.height,rect.width,rect.height));
                core->rWindow.draw(m_sprite);
                core->fontRenderer->printCenteredString(m_displayString, rect, sf::Color(0,0,0),24);
                break;
            case 1://HOVER on mouse on
                m_sprite.setTextureRect(sf::IntRect(0,0,rect.width,rect.height));
                core->rWindow.draw(m_sprite);
                core->fontRenderer->printCenteredString(m_displayString, rect, sf::Color(255,255,255),24);
                break;
            case 2://ACTIVE on left click
                m_sprite.setTextureRect(sf::IntRect(0,2*rect.height,rect.width,rect.height));
                core->rWindow.draw(m_sprite);
                core->fontRenderer->printCenteredString(m_displayString, rect, sf::Color(255,255,255),24);
                break;
        }
    }
}
